Base address of unit object array is at address [54F848]
Unit objects are 120 bytes long.


OK, this file just went to hell since I figured out after I started it that different units
have very different meanings for the data at the same offsets. There is definately some sort
of inheritance hierarchy, but I don't know what it really is yet. I'm pretty sure there is
some sort of "Vehicle" and "Building" class somewhere in the list, and definately a base class
for all of them. Likely also some sort of "Military Vehicle" too.



Offset 	Size 	Description
------ 	---- 	-----------
0x00	4	vtbl
0x04	4	Unit* next  [-1 = IsDead, -2 = InGarage]
0x08	4	Unit* prev  [union { SavedGames: uint prevIndex, IsDead: uint deadTick, Other: Unit* prev}]
0x0C	4	Unit* playerNext [UnitOfSameType: Vehicle/Building/Other] (All units from the same player. Note: this list is built backwards)
0x10	4	int unitIndex
0x14	4	int pixelX
0x18	4	int pixelY
0x1C	1	uint8 rotation  [of chasis] [0-255 is facing right/east, and increases counterclockwise]
0x1D	1	uint8 ownerAndCreatorNum
	.0	.4 bits	ownerNum  [playerNum] [lower 4 bits]
	.4	.4 bits	creatorNum  [playerNum] [upper 4 bits]
0x1E	2	short damage  [SetDamage]
0x20	1	bool busy
0x21	1	uint8 command  [CommandPacket.type] [IsBusy]
0x22	1	uint8 action  (what the unit is currently doing, as opposed to what it's been ordered to do)
0x23	1	uint8 executingAction  (sorry, hard to be clear on this)
0x24	2	short cargoOrWeapon  [GetWeapon/GetCargo], tubeOrWallType being built by an Earthworker
0x26	2	short attackingUnitIndex  (unit that is attacking this one)
0x28	4
0x2C	2	short unitTypeInstanceNum ("%s # %i-%02i", this is the last number printed)
0x2E	2	short reloadTimer
0x30	
0x34	4	destWaypoints* stuct/class
0x38	4	destWaypoints* ???  (this description could be wrong)
0x3C	4	int actionTimer
0x40	4	struct animationAndFrameIndex
	.0	.16	 ushort animationIndex  [Zero extended]
	.16	.15	 ushort frameIndex  [15 bits, zero extended]
0x44	4	struct flags (See below for descriptions of bits)

0x4E	2	short timerStickyfoam
0x50	2	short timerEMP

0x4F	1	(SetCargo)

0x68	4	Object on Pad (GetObjectOnPad)


Unit
----
Note: Constructor sets flags to 0

Offset 	Size 	Description
------ 	---- 	-----------
0x44	4	flags


Unit:PlayerUnit
---------------
Note: Constructor sets flags to 0x00000400

Offset 	Size 	Description
------ 	---- 	-----------


Unit:PlayerUnit:Building
------------------------
Note: Constructor sets flags to 0x20000404

Offset 	Size 	Description
------ 	---- 	-----------
0x34	4	
	.16	 animationIndex
0x38	4	???* ???  [Object is used to calc DIRT dmg prevention]
0x3C	4	
0x40	4	animationAndFrameIndex
	.16	 animationIndex
	.15	 frameIndex

0x50	4	animationAndFrameIndex  [copied from 0x40]
0x54	2	
0x56	2	
0x58	2	

[vtbl+0xBC]	void DoDisable?() (because of power?)
[vtbl+0xD0]	int GetPowerProduction() (includes power morale bonus from M_POW_BONUS)
[vtbl+0xE0]	int GetProductionRate()
[vtbl+0xE4]	int ???()
[vtbl+0xE8]	int GetNumWorkersRequired()
[vtbl+0xF0]	int GetPowerRequired()

Unit:PlayerUnit:Building:Garage
-------------------------------
0x60	4*6	bay[6]  [union { Unit* unit, uint unitIndex }]

Unit:PlayerUnit:Vehicle
-----------------------
Note: Constructor sets flags to 0x00000402

Offset 	Size 	Description
------ 	---- 	-----------
0x34	4	???*
0x38	4	

0x54 	2	stickyfoamTimer
0x56	2	empTimer
0x58 	2	???Timer?
0x5E	2	garageLoadedTick  [probably used to calculate repair time]
0x60	2	stickyfoamedTick  [probably used to calculate duration or end time]


Unit:PlayerUnit:Vehicle:Earthworker
-----------------------------------
0x24	2	map_id tubeOrWallType  [cargoOrWeapon]
0x62	8	Rect tubeOrWallRect


Unit:PlayerUnit:Vehicle:Tank
----------------------------
0x2D	1	turretRotation
0x32	1	???
0x33	1	turretFrameIndex
0x40 	4 	animationAndFrameIndex [short animationIndex [lower 15 bits], short frameIndex [upper 16 bits]]


Unit:Vehicle:Construction  [ConVec, RoboMiner, GeoCon]
-------------------------
0x62 	2 	buildArea.TopLeft.x
0x64 	2 	buildArea.TopLeft.y
0x66 	2 	buildArea.BottomRight.x
0x68 	2 	buildArea.BottomRight.y
0x6A 	2 	scStubIndex  [BuildGroup]


Unit:Building:Lab
-----------------
Offset 	Size 	Description
------ 	---- 	-----------
0x24 	2 	Amount of time until next research increment (research progresses in chunks)
0x3C 	4 	Amount of research left to complete tech (intialized to costOfResearch*256 when research starts)
0x60 	4 	techNum being researched
0x64 	1 	numScientists researching at the lab


Unit:Building:Factory
---------------------
Offset 	Size 	Description
------ 	---- 	-----------
0x60	1	map_id itemToProduce
0x61	6?	char[6?] cargoBayContents
0x6C	2	scStubIndex  [BuildGroup]



Unit:Building:Spaceport
-----------------------
0x6E	4	launchPadUnitType  [SULV/RLV/EMPMissile]
0x72	2	launchCargo
0x74	2	boolRLVLanding


Unit:EMPMissile
---------------
0x34	4	destPixelX
0x38	4	destPixelY

0x54	4	meteorDefenseIndex


Unit:Weapon
-----------
0x34	4	destPixelX
0x38	4	destPixelY
0x3C	4	

0x48	4	sourceUnitIndex  [Tank/GP that created this weapons fire]

0x54	1	creatorPlayerBitMask  [from creatorNum of source unit]

0x5A	1	allyBitMask

0x5C	4	


Unit:MiningBeacon
-----------------
0x58	4	int numTruckLoadsSoFar
0x5C	4	int barYield
0x60	4	int variant
0x64	1	char oreType  [0 = common, 1 = rare]
0x65	1	
0x66	1	
0x67	1	char surveyedBy  [player bit vector]


Unit:Disaster:Vortex
--------------------
0x58	4	directionChangeStartTick (makes smooth transitions for the cloud column position)
0x5C	1	directionOfMovement (0-0xFF, 0 = right, 0x40 = down, 0x80 = left, 0xC0 = up)
0x5D	2	
0x5F	2	

0x65	2	
0x67	2	

[vtbl+0x80]	Function which controls movement of vortexes.


Unit:Disaster:Meteor
--------------------
0x34	2	destTileX
0x36	2	destTileY


Vtbl Functions
--------------

# 	Offset 	Function Description
- 	------ 	--------------------
0x0	0x00 	UnitTypeInfo* GetUnitTypeInfo()
0x1	0x04 	void ProcessForGameCycle()
0x2	0x08 	int ProcessTimers()
0x3	0x0C 	bool CheckSpontaneouslyExplode()
0x4	0x10 	int FireWeapon()
0x5	0x14 	void ?(???, ???)
0x6	0x18	void DrawUnit(Viewport* viewport)
0x7	0x1C	void LightUpVisibleRange(Viewport?* viewport?)
0x8	0x20	
0x9	0x24	
0xA	0x28	
0xB	0x2C	
0xC	0x30	
0xD	0x34	int Select(int pixelX, int pixelY)
0xE	0x38	int MouseOver(int pixelX, int pixelY) - called every game cycle if the mouse if over the unit's bounding box. The pixel coordinates are relative to the upper left corner of the unit's bounding box.
0xF	0x3C	int GetRolloverText(char *destBuffer, int bufferSize) - returns the text string that is displayed when the mouse is left resting over a unit for a second. This function returns the return value of snprintf, or 0 if snprintf is not called.
0x10	0x40	int GetSelectedUnitDisplayString(char *destBuffer, int bufferSize) - returns the selected unit text string of the form "%s # %i-%02i". This function returns the return value of snprintf.
0x11	0x44	
0x12	0x48	
0x13	0x4C	Unit* Release(int ???)
0x14	0x50	
0x15	0x54	
0x16	0x58	
0x17	0x5C	void EMPed(short empTime)
0x18	0x60	void Stickyfoamed(int stickyfoamTime)
0x19	0x64	void Move()
0x1A	0x68	
0x1B	0x6C	void GetLocation(int unused, int unused, int* tileX, int* tileY)


Flags
-----
Bit# 	Bit Mask 	Description
---- 	-------- 	-----------
0x00 	0x00000001 	LightsOn  [0 = off, 1 = on]
0x01 	0x00000002 	IsVehicle
0x02 	0x00000004 	IsBuilding
0x03 	0x00000008 	
0x04 	0x00000010 	IsOffensive (1 = show attack/patrol buttons, 0 = no buttons)
0x05 	0x00000020 	DoubleFireRate - used by dual turret weapon platforms
0x06 	0x00000040 	(If 0 and !IsVehicle, does "moDelSelf" on "ctMoDeath")
0x07 	0x00000080 	WeaponConnectedToCC (Used for 150% GP damage)
0x08 	0x00000100 	CanExplode?
0x09 	0x00000200 	
0x0A 	0x00000400 	(Cleared when a ConVec starts building, [moObjFroze])
0x0B 	0x00000800 	
0x0C 	0x00001000 	IsEden  [Used to display correct chasis for combat vehicles]
0x0D 	0x00002000 	DisasterDetected / EnabledPower
0x0E 	0x00004000 	DisasterNoFirstWarn 	(Used by SetTornado) / EnabledWorkers
0x0F 	0x00008000 	DisasterNoSecondWarn 	(Used by SetTornado) / EnabledScientists
0x10 	0x00010000 	DoAfterShock [Earthquake]
0x11 	0x00020000 	IsDead (used by IsLive)
0x12 	0x00040000 	IsStickyfoamed - Set if unit is locked down by stickyfoam (Also needs timer set properly, timer>0)  [Building: IsInfected]
0x13 	0x00080000 	IsEMPed - Set if unit is disabled by EMP (timer will cound down until worn off)
0x14 	0x00100000 	IsESGed - Set if unit is currently affected by ESG
0x15 	0x00200000 	
0x16 	0x00400000 	PreventExplosionOnDeath - Prevents an EMP blasts, and harmful explosions (Buildings only)
0x17 	0x00800000 	(SetOppFiredUpon) - Enemy military units will attack this unit without being ordered to (only works on buildings)
0x18 	0x01000000 	IsUndocking  [Convec/CargoTruck? being moved up out of the storage bay after pickup/dropoff]
0x19 	0x02000000 	HasSpecialTarget  [ClearSpecialTarget, CreateSpecialTarget]
0x1A 	0x04000000 	
0x1B 	0x08000000 	ForceFullLightVisibility?
0x1C 	0x10000000 	IsInvisibile (for disasters (and structures) (before they appear, they exits))
0x1D 	0x20000000 	HasSpecialTarget? (do not auto target)
0x1E 	0x40000000 	
0x1F 	0x80000000 	


